from model.user import User
class UserDao(object):
    def __init__(self, session):
        self.session = session

    def add(self, user):
        self.session.add(user)

    def get_by_id(self,user_id):
       return self.session.query(User).filter(User.user_id==user_id).first()

    def get_by_tel(self,tel):
        try:
            return self.session.query(User).filter(User.tel == tel).first()
        except Exception as ex:
            raise  ex
            return None
    def get_by_openid(self,openid,user_type=1):
        try:
            return self.session.query(User).filter(User.openid==openid) \
                .filter(User.user_type == int(user_type)) \
                .first()
        except Exception as ex:
            raise ex;









